package com.bz.sunmipay.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.baizhi.baseapp.adapter.BasePageAdapter;
import com.baizhi.baseapp.util.CalendarUtils;
import com.bz.sunmipay.R;
import com.bz.sunmipay.model.PaymentDetail;
import com.sunmi.pay.hardware.aidlv2.AidlConstantsV2;

/**
 * DESC
 * <p>
 * Created by Administrator on 2019/12/6.
 */
public class PaymentDetailAdapter extends BasePageAdapter<PaymentDetail> {

    public PaymentDetailAdapter(Context ctx) {
        super(ctx);
    }

    @Override
    protected int getResource(int position) {
        return R.layout.payment_detail_item;
    }

    @Override
    protected void renderConvertView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = (ViewHolder) convertView.getTag();
        if (holder == null) {
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        }

        PaymentDetail item = getItem(position);
        holder.payment_amount.setText("€" + item.amount);
        holder.payment_date.setText(CalendarUtils.getTimeForYYYMMDD(Long.valueOf(item.date)));
        //成功
        if ("1".equals(item.paymentResult)) {
            holder.payment_result.setText("Complete");
        }
        //取消
        else if ("-1".equals(item.paymentResult)) {
            holder.payment_result.setText("Cancel");
        } else {
            holder.payment_result.setText("Fail");
        }

        //现金支付
        if ("-1".equals(item.paymentType)) {
            holder.payment_type.setText("Cash");
        } else if (String.valueOf(AidlConstantsV2.CardType.NFC.getValue()).equals(item.paymentType)) {
            holder.payment_type.setText("NFC");
        } else if (String.valueOf(AidlConstantsV2.CardType.IC.getValue()).equals(item.paymentType)) {
            holder.payment_type.setText("IC");
        } else if (String.valueOf(AidlConstantsV2.CardType.MAGNETIC.getValue()).equals(item.paymentType)) {
            holder.payment_type.setText("MAGNETIC");
        } else {
            holder.payment_type.setText("Unknown");
        }
    }

    private class ViewHolder {
        TextView payment_result;
        TextView payment_type;
        TextView payment_amount;
        TextView payment_date;

        ViewHolder(View convertView) {
            payment_type = convertView.findViewById(R.id.payment_type);
            payment_result = convertView.findViewById(R.id.payment_result);
            payment_amount = convertView.findViewById(R.id.payment_amount);
            payment_date = convertView.findViewById(R.id.payment_date);
        }
    }
}
